home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TC / PLAYVOCM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  4.1 KB  |  147 lines

  1. /*********************************************************************
  2. *
  3. *  PROGRAM NAME: PLAYVOCM.C
  4. *
  5. *  COMPILER:     Borland/Turbo C/C++
  6. *
  7. *  DESCRIPTION: Plays a .VOC file from the conventional memory using
  8. *               the CT-VOICE.DRV driver (accessed from SBSIM).  To run
  9. *               the program, type the following at the command line:
  10. *
  11. *               PLAYVOCM FILENAME
  12. *
  13. *               Where FILENAME is the drive/path/filename of the .VOC
  14. *               file to play.
  15. *
  16. *  NOTE:        SBSIM driver must be loaded before running this program.
  17. *
  18. *  WARNING:     This program does NOT support files larger than 64KB!
  19. *
  20. *********************************************************************/
  21. #define HEADER_OFFSET   0x1A
  22. #define VOC_MEM_DRIVER  0x04
  23.  
  24. #include <ctype.h>
  25. #include <conio.h>
  26. #include <fcntl.h>
  27. #include <stdio.h>
  28. #include <io.h>
  29. #include "drvrfunc.c"
  30. #include "drvrfunc.h"
  31.  
  32.  
  33. /********************************************************************/
  34. void main(int argc, char **argv)
  35. {
  36.   char  *Buffer,
  37.      Command,
  38.      UserQuit;
  39.  
  40.   long   Filesize;
  41.   int    FileHandle;
  42.   SIMERR RetValue;
  43.  
  44.   if (argc != 2)  // argc = no. of parameters entered on command line
  45.   {
  46.     puts("Command line must contain EXACTLY ONE filename parameter!");
  47.     return;  // Terminate program
  48.   }
  49.  
  50.  
  51.   /*--- SEE IF SBSIM DRIVER HAS LOADED ------------*/
  52.   SIMint = FindDvr("SBSIM", 0x0103);  // Get SBSIM's interrupt no.
  53.   if (SIMint == 0)
  54.   {
  55.     puts("SBSIM driver not loaded!");
  56.     return;  // Terminate program
  57.   }
  58.  
  59.   /*--- SEE IF CT-VOICE.DRV DRIVER HAS LOADED -------*/
  60.   if (!(GetDrvrs() & VOC_MEM_DRIVER))
  61.   {
  62.     puts("CT-VOICE.DRV not loaded!");
  63.     return;  // Terminate program
  64.   }
  65.  
  66.  
  67.   /*--- OPEN FILE SPECIFIED ON COMMAND LINE (STORED IN argv[1] ------*/
  68.   if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
  69.   {
  70.     printf("FILE: %s not successfully opened!\n", argv[1]);
  71.     return;  // Terminate program
  72.   }
  73.  
  74.   /*--- GET THE FILE SIZE -------------------------*/
  75.   Filesize = filelength(FileHandle);
  76.   if (Filesize > 65535)
  77.   {
  78.     puts("File size > 64KB not supported!");
  79.     return;  // Terminate program
  80.   }
  81.  
  82.  
  83.   /*--- ALLOCATE BUFFER AND LOAD IT FROM FILE -----------*/
  84.   if ((Buffer = (char *) malloc((size_t) Filesize)) == NULL)
  85.   {
  86.     puts("Memory buffer not allocated!");
  87.     _close(FileHandle);
  88.     return;  // Terminate program
  89.   }
  90.   _read(FileHandle, (void *) Buffer, (unsigned) Filesize);
  91.   _close(FileHandle);  // Done with the file, close it!
  92.  
  93.  
  94.   /*--- StartSnd() INITIALIZES THE CT-VOICE DRIVER -----------*/
  95.   RetValue = StartSnd(MemVoice, (void far *) (Buffer + HEADER_OFFSET), NULL,
  96.               NULL);
  97.   if (RetValue != SIMerr_NoErr)
  98.   {
  99.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  100.     free(Buffer);  // Deallocate memory allocated by malloc()
  101.     return;  // Terminate program
  102.   }
  103.  
  104.   /*--- StartSnd() BEGINS PLAYING OF THE FILE ----------*/
  105.   RetValue = PlaySnd(MemVoice);
  106.   if (RetValue != SIMerr_NoErr)
  107.   {
  108.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  109.     free(Buffer);  // Deallocate memory allocated by malloc()
  110.     return;  // Terminate program
  111.   }
  112.  
  113.  
  114.   clrscr();  // Clear screen
  115.   printf("\n\n\n\n\n     SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
  116.   printf("                   (P)ause\n");
  117.   printf("                   (R)esume\n");
  118.   printf("                   (Q)uit\n");
  119.  
  120.   UserQuit = FALSE;
  121.  
  122.   /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
  123.   do
  124.   {
  125.     if (kbhit())  // Was a key pressed?
  126.     {
  127.  
  128.       Command = toupper(getch()); // Get char typed & convert to upper case
  129.       if (Command == 'P')
  130.     PauseSnd(MemVoice);
  131.       else if (Command == 'R')
  132.     ResumeSnd(MemVoice);
  133.       else if (Command == 'Q')
  134.     UserQuit = TRUE;
  135.     }
  136.     // Exit do-while loop if file is done playing or user typed 'Q'
  137.   } while (GetSndStat(MemVoice) != 0 && UserQuit == FALSE);
  138.  
  139.  
  140.   /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
  141.   if (GetSndStat(MemVoice) != 0 && UserQuit == TRUE)
  142.     StopSnd(MemVoice);
  143.  
  144.   free(Buffer);  // Deallocate memory allocated by malloc()
  145.   return;
  146. }
  147.